<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>账户 新增</title>
<jsp:include page="../../import.jsp" flush="true"/>
</head>
<body>
		<form id="mcrLoanChannel_form">
            <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
                <div class="fieldBox col_50">
                    <div class="label">机构编码</div>
                    <div class="field">
                        <input name="loanChannel" id="loanChannel" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:100}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">机构名称</div>
                    <div class="field">
                        <input name="loanName" id="loanName" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:500}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">待还本金</div>
                    <div class="field">
                        <input name="remainAmt" id="remainAmt" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:500, digits:true}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">路由排序</div>
                    <div class="field">
                        <input name="sort" id="sort" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:500, digits:true}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">绑卡排序</div>
                    <div class="field">
                        <input name="bankSort" id="bankSort" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:500, digits:true}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">授信占比</div>
                    <div class="field">
                        <input name="creditWeight" id="creditWeight" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:500, digits:true}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">统一社会信用代码</div>
                    <div class="field">
                        <input name="societyCreditCode" id="societyCreditCode" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:500}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                 <div class="fieldBox col_50">
                    <div class="label">是否启用</div>
                    <div class="field">
                       <select name="isValid" id="isValid">
	                		<option value="1">是</option>
	                		<option value="0">否</option>
	                	</select>
                    </div>
                </div>
                <!-- hide data -->
		        <div class="fieldBox col_100" style="display:none;">
		          <div class="field">
		              <input name="dataId" id="dataId" type="text" class="ui-textbox" value="${id}">
		          </div>
		        </div>
            </div>
        </form>
	<script>
		$(function() {
		   $("#mcrLoanChannel_form").ligerForm({
                validate: true
           });
	       initData();
		});
		
		//定义父级调用事件
		frameElement.dialog.onOk = function () {
			save();
		}
		
		frameElement.dialog.onCancel = function () {
			frameElement.dialog.close();
		}
		
		//保存
		function save(){
			var ligerForm = liger.get("mcrLoanChannel_form");
            if (!ligerForm.valid()) {
                UIUtils.alertWarning("有验证信息未通过!");
                return; //验证不通过，不执行以下代码
            }
            var data = ligerForm.getData();
            var dataId = $("#dataId").val();
            var url = '<%=path%>/mcr/mcrLoanChannel/add.do';
            if(StringUtils.isNotEmpty(dataId)){
            	url = '<%=path%>/mcr/mcrLoanChannel/modify.do';
            	data["id"]= dataId;
            }
            AjaxUtils.ajaxPost(url, data, addCallback);
		}
		
		
		//新增回调
		function addCallback(msg){
			if(msg.success == 1){
				 parent.grid.reload();
				 //parent.$.ligerDialog.SQalert({content:'提示内容', SQ_type: "success"});
				 UIUtils.alertSuccess("操作成功!");
				 frameElement.dialog.close();
			 }else{
				 UIUtils.alertError(msg.info);
			 }
		}
		
		//修改初始化数据
		function initData(){
			var dataId = $("#dataId").val();
	    	if(StringUtils.isEmpty(dataId))return;
	    	var _url = '<%=path%>/mcr/mcrLoanChannel/getById.do';
	    	AjaxUtils.ajaxGet(_url, {id:dataId}, initCallback);
    	}
		
		//初始化回调
		function initCallback(msg){
			if(msg.success == 1){
				 setData(msg.data);//设置数据
			 }else{
				 UIUtils.alertError(msg.info);
			 }
		}
		
		//修改时候设置页面数据
	    function setData(data){
	    	var form = new liger.get("mcrLoanChannel_form");
	    	form.setData({
	    		loanChannel:data.loanChannel,
	    		loanName:data.loanName,
                remainAmt:data.remainAmt,
                societyCreditCode:data.societyCreditCode,
	    		isValid:data.isValid,
                sort:data.sort,
                bankSort:data.bankSort,
                creditWeight:data.creditWeight,
	    	});
		};

        /**
         * 是否去除所有空格
         * @param str
         * @param is_global 如果为g或者G去除所有的
         * @returns
         */
        function Trim(str,is_global)
        {
            var result;
            result = str.replace(/(^\s+)|(\s+$)/g,"");
            if(is_global.toLowerCase()=="g")
            {
                result = result.replace(/\s/g,"");
            }
            return result;
        }

        /**
         * 空格输入去除
         * @param e
         * @returns {Boolean}
         */
        function inputSapceTrim(e,this_temp)
        {
            this_temp.value = Trim(this_temp.value,"g");
            var keynum;
            if(window.event) // IE
            {
                keynum = e.keyCode
            }
            else if(e.which) // Netscape/Firefox/Opera
            {
                keynum = e.which
            }
            if(keynum == 32){
                return false;
            }
            return true;
        }

        /**
         * 禁止空格输入
         * @param e
         * @returns {Boolean}
         */
        function banInputSapce(e)
        {
            var keynum;
            if(window.event) // IE
            {
                keynum = e.keyCode
            }
            else if(e.which) // Netscape/Firefox/Opera
            {
                keynum = e.which
            }
            if(keynum == 32){
                return false;
            }
            return true;
        }
    </script>

</body>
</html>